package Java0311;

import java.util.Scanner;

public class Array13 {
    public static void main(String[] args) {
        //福彩双色球的玩法分为红球和篮球（具体玩法百度）
        // 红球范围是1-33，蓝球是1-16。每注是6个红球不重复并按照升序顺序排列，加上一个蓝球。生成一注号码放入数组中，随机数的方法是Math.random()
        //定义一个长度为7的整形数组，存放一注
        Scanner scan = new Scanner(System.in);
        //存放随机生成的中将号码
        int[] array = new int[7];
        //存放彩民买的号码
        int[] number = new int[7];
        //接受随机数
        int random;
        //定义一个空瓶子
        int temp;
        //随机数字是否重复
        boolean repeat = false;
        //随机生成的红球号码,最后一位为蓝色号码。。。不允许出现重复
        for (int i = 0; i < array.length; i++) {
            repeat = false;
            random = (int) (Math.random() * 33 + 1);
            for (int j = 0; j < i; j++) {
                if (random == array[j]) {
                    repeat = true;
                    break;
                }
            }
            if (!repeat) {
                array[i] = random;
            } else {
                //循环变量减一
                i--;
            }
            if (i == array.length - 1) {
                random = (int) (Math.random() * 16 + 1);
                array[array.length - 1] = random;
            }
        }
        //对随机生成的中奖号码排序，只对把红球升序排列
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 2 - i; j++) {
                if (array[j] > array[j + 1]) {
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
//        //打印随机生成的中奖号码
//        System.out.println("中奖号码：");
//        for (int i = 0; i < array.length; i++) {
//            System.out.print(array[i] + "\t");
//        }
        System.out.println();
        //用户输入想买的彩票号码
        System.out.println("请输入6个不重复的红球号码(1-33的整数)：");
        for (int i = 0; i < number.length; i++) {
            if (i == number.length - 1) {
                System.out.println("请输入1个蓝球号码（1-16的整数）：");
                number[number.length - 1] = scan.nextInt();
            } else {
                number[i] = scan.nextInt();
            }
        }
        //对用户买的号码进行排序，只对红球升序排列
        for (int i = 0; i < number.length - 1; i++) {
            for (int j = 0; j < number.length - 2 - i; j++) {
                if (number[j] > number[j + 1]) {
                    temp = number[j];
                    number[j] = number[j + 1];
                    number[j + 1] = temp;
                }
            }
        }
        //打印随机生成的中奖号码
        System.out.println("中奖号码：");
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + "\t");
        }
        System.out.println();
        //打印用户买的号码
        System.out.println("用户购买的号码：");
        for (int i = 0; i < number.length; i++) {
            System.out.print(number[i] + "\t");
        }
        System.out.println();

        //统计红球相同的数字个数.。。。。。存在错误，不能仅对应位置相同数字才算
        int count = 0;
        //判断中奖情况
        for (int i = 0; i < number.length - 1; i++) {
            if (number[i] == array[i]) {
                count++;
            }
        }
        System.out.println("中奖情况：");
        if (count == 6 && number[number.length - 1] == array[array.length - 1]) {
            System.out.println("一等奖！");
        } else if (count == 6) {
            System.out.println("二等奖");
        } else if (count == 5 && number[number.length - 1] == array[array.length - 1]) {
            System.out.println("三等奖");
        } else if ((count == 5) || (count == 4 && number[number.length - 1] == array[array.length - 1])) {
            System.out.println("四等奖");
        } else if (count == 4 || (count == 3 && number[number.length - 1] == array[array.length - 1])) {
            System.out.println("五等奖");
        } else if ((count == 2 && number[number.length - 1] == array[array.length - 1]) || (count == 1 && number[number.length - 1] == array[array.length - 1]) || number[number.length - 1] == array[array.length - 1]) {
            System.out.println("六等奖");
        } else {
            System.out.println("屁也没中！！！");
        }
    }
}

